﻿using System.Web.Mvc;
using Ext.Net;
using Ext.Net.MVC;
using Sharp.Infrastructure.WebApiClient;
using Sharp.Portal.ExtNet;
using Sharp.Portal.Mvc;
using Sharp.ServiceContracts;
using Sharp.WebBooter.Areas.Workflow.Models;

// ReSharper disable Mvc.ViewNotResolved

namespace Sharp.WebBooter.Areas.Workflow.Controllers
{
    [Authorize]
    [AutomaticTemplate]
    public class TaskController : SharpController
    {
        /// <summary>
        /// 待处理
        /// </summary>
        /// <returns></returns>
        public ActionResult Index(string containerId)
        {
            return new Ext.Net.MVC.PartialViewResult
            {
                Model = new TaskIndexModel()
                {
                },
                ContainerId = containerId,
                RenderMode = RenderMode.AddTo
            };
        }
        /// <summary>
        /// 已完成
        /// </summary>
        /// <returns></returns>
        public ActionResult Completed(string containerId)
        {
            return new Ext.Net.MVC.PartialViewResult
            {
                Model = new TaskIndexModel()
                {
                    StoreUrlAction = "GetCompletedPaged"
                },
                ContainerId = containerId,
                RenderMode = RenderMode.AddTo
            };
        }
        /// <summary>
        /// 分页数据
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public ActionResult GetPaged(ExtRequestParameters parameters)
        {
            using (var proxy = new WebApiClientServiceProxy<IWorkflowService>())
            { 
                var pageInfo = proxy.Channel.GetReadyTasksPaged(parameters.ToPagingFeature());

                return this.Store(pageInfo.Data, pageInfo.TotalRecords);
            }
        }

        /// <summary>
        /// 分页数据
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public ActionResult GetCompletedPaged(ExtRequestParameters parameters)
        {
            using (var proxy = new WebApiClientServiceProxy<IWorkflowService>())
            {
                var pf = parameters.ToPagingFeature();

                var pageInfo = proxy.Channel.GetCompletedTasksPaged(pf);

                return this.Store(pageInfo.Data, pageInfo.TotalRecords);
            }
        }

    }
}